<template>
    <div class="icons">
      <swiper >
         <swiper-slide v-for="(page,index) of pages" :key="index"><!--pages 总的轮播页面-->
          <div class="icon" v-for="item of page" :key="item.id">
             <div class="icon-img">
               <img class="icon-img-content" :src="item.imagUrl"/>
             </div>
             <p class="icon-desc">{{item.desc}}</p>
          </div>
         </swiper-slide>
      </swiper>
    </div>
</template>

<script>
export default {
  name: 'HomeIcons',
  data () {
    return {
      iconList: [{
        id: '001',
        imagUrl: 'http://img1.qunarzz.com/piao/fusion/1803/95/f3dd6c383aeb3b02.png',
        desc: '热门景点'
      }, {
        id: '002',
        imagUrl: 'http://img1.qunarzz.com/piao/fusion/1803/6a/45f595250c73d102.png',
        desc: '夏日玩水'
      }, {
        id: '003',
        imagUrl: 'http://img1.qunarzz.com/piao/fusion/1803/e3/67df61427c8e1302.png',
        desc: '云南映象'
      }, {
        id: '004',
        imagUrl: 'http://img1.qunarzz.com/piao/fusion/1803/96/c70f1e85ae4a4f02.png',
        desc: '石林'
      }, {
        id: '005',
        imagUrl: 'http://img1.qunarzz.com/piao/fusion/1804/ff/fdf170ee89594b02.png',
        desc: '昆明必游'
      }, {
        id: '006',
        imagUrl: 'http://img1.qunarzz.com/piao/fusion/1805/57/1e29afd06f881102.png',
        desc: '游云南'
      }, {
        id: '007',
        imagUrl: 'http://img1.qunarzz.com/piao/fusion/1803/75/eca3ce656c886502.png',
        desc: '普者黑'
      }, {
        id: '008',
        imagUrl: 'http://img1.qunarzz.com/piao/fusion/1803/b1/528a9e80403b8c02.png',
        desc: '七彩云南'
      }, {
        id: '009',
        imagUrl: 'http://img1.qunarzz.com/piao/fusion/1804/5a/13ceb38dcf262f02.png',
        desc: '一日游'
      }]
    }
  },
  computed: {
    pages () { // 返回一个二进制数组
      const pages = []
      this.iconList.forEach((item, index) => {
        const page = Math.floor(index / 8)
        if (!pages[page]) {
          pages[page] = []
        }
        pages[page].push(item) // 向数组的末尾添加一个或多个元素，并返回新的长度。
      })
      return pages
    }
  }
}
</script>

<style lang="stylus"  scoped>
  @import "~styles/varibles.styl"
  @import "~styles/mixins.styl"
  .icons
    overflow: hidden
    height: 0
    padding-bottom 50%
    .icon
      position: relative
      overflow: hidden
      float left
      width 25%
      height 0
      padding-bottom 25%
      .icon-img
        position: absolute
        left 0
        right 0
        bottom: .44rem
        top: 0
        box-sizing border-box
        padding: .1rem
        .icon-img-content
          display bolock
          margin 0 auto
          height: 100%
      .icon-desc
        position: absolute
        left 0
        right 0
        bottom 0
        height .44rem
        line-height .44rem
        text-align center
        color: $darkTextColor
        ellipsis()
</style>
